home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 340 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: solon.com!not-for-mail
  2. From: sl14@crux3.cit.cornell.edu (S. Lee)
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion.
  5. Date: 21 Feb 1996 08:13:00 -0600
  6. Organization: Nekomi Institute of Technology
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4gf99c$1fp@solutions.solon.com>
  10. References: <4fstj7$2l6@solutions.solon.com> <4fvgvb$e0t@solutions.solon.com> <4g55fl$avl@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4g55fl$avl@solutions.solon.com>,  <msb@sq.com> wrote:
  14. >> > short test(short x1, short x2) {
  15. >> >  short result;
  16. >> >  result = x1 + x2;
  17. >> 
  18. >> The addition operator "+" converts your short operands to ints.
  19. >
  20. >No, just using their values does that.  The operator + never sees
  21. >operands narrower than int.  In the statement
  22. >    x1; 
  23. >the short is converted to int before being discarded.
  24.  
  25. Okay, I'm confused.  Let just say the above is true.  Then the expression
  26. "x1 + x2" has type int because x1 and x2 were converted to int before
  27. being passed to the + operator.
  28.  
  29. So what if sizeof(short) == sizeof(int)?  Assuming both x1 and x2 are
  30. non-negative, would "x1 + x2" be unsigned int if it wouldn't fit in an
  31. int?  In short, would there be undefined/implementation defined behaviour
  32. if "result" is unsigned int?  How about long?
  33.  
  34. sl14@cornell.edu
  35. Witty .sig under construction.
  36.